package com.ruoyi.controller.masterdate;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.jpjs.param.ParamService;
import com.ruoyi.service.jpjs.person.PersonService;
import com.ruoyi.service.masterdate.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/company")
public class CompanyController extends BaseController {

    private String prefix = "masterdate/company";

    @Autowired
    private CompanyService companyService;

    @GetMapping()
    public String person() {
        return prefix + "/Company";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findCompanyAll(@RequestParam Map<String, Object> map) {
        List<Map<String, Object>> list = companyService.findCompanyAll(map);
        return getDataTable(list);
    }

    @GetMapping("/add")
    public String addCompany(ModelMap mmp) {
        mmp.put("parent",companyService.findCompanyAll(null));
        return prefix + "/add";
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addCompany(@RequestParam Map<String, Object> map) {
        return toAjax(companyService.addCompany(map));
    }

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editCompany(@RequestParam Map<String, Object> map) {
        return toAjax(companyService.editCompany(map));
    }

    @GetMapping("/edit/{id}")
    public String editCompany(@PathVariable("id") String id, ModelMap mmp) {
        mmp.put("parent",companyService.findCompanyAll(null));
        mmp.put("company", companyService.findCompany(id));
        return prefix + "/edit";
    }

    @PostMapping("/checkCodeUnique")
    @ResponseBody
    public int checkCodeUnique(@RequestParam Map<String, Object> map) {
        return companyService.checkCodeUnique(map);
    }
}
